

import requests
from loguru import logger


class MerchantCoupon:
    def __init__(self):
        self.token = "merchant189e2e63af044d5c80578802548f5dde"

    def merchant_coupon_list(self):
        """
        优惠券列表
        """
        url="https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/list"
        params = {
            'page': '1',
            'limit': '20',
            'status': '0',
            'name': '1',
            'type': '',
            'useType': '',
            'receiveType': '1',
            'category': '1',
            'temp': '1756108501',
        }
        headers = {'authori-zation': self.token}
        logger.info(f"接口{self.merchant_coupon_list.__name__}请求信息为{params}")
        response = requests.get(url,params=params,headers=headers,)
        logger.info(f"接口{self.merchant_coupon_list.__name__}响应信息为{response.json()}")
        return response.json()

    def merchant_coupon_save(self):
        """
        优惠券新增
        """
        headers = {'authori-zation': self.token}

        json_data = {
            'category': 1,
            'isFixedTime': False,
            'name': '2',
            'money': 1,
            'minPrice': 0,
            'day': 1,
            'isTimeReceive': False,
            'productIds': '',
            'receiveType': 2,
            'isLimited': False,
            'useStartTime': '',
            'useEndTime': '',
            'receiveStartTime': '',
            'receiveEndTime': '',
            'sort': 1,
            'total': 0,
            'status': False,
            'checked': [],
        }

        response = requests.post(
            'https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/save',
            headers=headers,
            json=json_data,
        )

    def merchant_coupon_delete(self):
        """
        优惠券删除
        """
        headers = {
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'authori-zation': 'merchant189e2e63af044d5c80578802548f5dde',
            # 'content-length': '0',
            'origin': 'https://adminmer.merchant.java.crmeb.net',
            'priority': 'u=1, i',
            'referer': 'https://adminmer.merchant.java.crmeb.net/',
            'sec-ch-ua': '"Not;A=Brand";v="99", "Microsoft Edge";v="139", "Chromium";v="139"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0',
        }

        response = requests.post('https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/delete/1303',
                                 headers=headers)

    def merchant_coupon_status(self):
        """
        优惠券状态更新
        """
        headers = {
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'authori-zation': 'merchant189e2e63af044d5c80578802548f5dde',
            # 'content-length': '0',
            'origin': 'https://adminmer.merchant.java.crmeb.net',
            'priority': 'u=1, i',
            'referer': 'https://adminmer.merchant.java.crmeb.net/',
            'sec-ch-ua': '"Not;A=Brand";v="99", "Microsoft Edge";v="139", "Chromium";v="139"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0',
        }

        response = requests.post(
            'https://api.admin.merchant.java.crmeb.net/api/admin/merchant/coupon/update/status/1321',
            headers=headers,
        )

if __name__ == '__main__':
    order=MerchantCoupon()
    order.merchant_coupon_list()
